<?php

function sendNotificationEmail($message, $subject, $toemail, $toname, $fromemail = "", $fromname = ""){
	static $phpmailer;
        
    if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) 
		$phpmailer = new PHPMailer();
      
      
    $phpmailer->ClearAllRecipients();
    $phpmailer->ClearAttachments();
    
    if($fromemail == ""){
   
    	$phpmailer->From = MAIL_FROM;
    	$phpmailer->FromName = MAIL_FROM_NAME;
    }
    else{
    	
    	$phpmailer->From = $fromemail;
    	$phpmailer->FromName = $fromname;
    }
    
	$phpmailer->AddAddress($toemail, $toname);                 
	$phpmailer->Subject =  utf8_decode($subject);

	$phpmailer->IsHTML(true);      
	$phpmailer->Body = utf8_decode($message);
	$phpmailer->IsSMTP();
	$phpmailer->Host = SMTP_HOST;
	$phpmailer->SMTPAuth = true;
	$phpmailer->Username = SMTP_USER;
	$phpmailer->Password = SMTP_PASSWORD;
	$phpmailer->Port = SMTP_PORT;
    $return = $phpmailer->Send();
    
    if (!$return )
    {
        return 'PHPMailer error: ' . $phpmailer->ErrorInfo;
	}   
    return TRUE;

}

?>
